package com.jason.controller;

import com.jason.domain.Student;
import com.jason.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StuService service;
    @RequestMapping("/manage")
    public String manage(HttpServletRequest request){
        List<Student> list=service.list();
        request.setAttribute("list",list);
        return "manage";
    }
    @RequestMapping("/delete")
    public String delete(Integer id) {
        int i = service.delete(id);
        if (i > 0) {
            return "forward:manage";
        } else {
            return "fail";
        }
    }
    @RequestMapping("/savePage")
    public String savepage(){
        return "save";
    }
    @RequestMapping("/save")
    public String save(Student student){
    int i=service.save(student);
        if (i >0) {
            return "forward:manage";
        }else {
            return "fail";
        }
    }
}
